<template>
  <div class="cart-page">
    <div class="page-header">
      <h1>购物车</h1>
      <router-link :to="{ name: 'ProductList' }" class="continue-shopping"> 继续购物 </router-link>
    </div>

    <div v-if="cartStore.isEmpty" class="empty-cart">
      <div class="empty-cart-icon">🛒</div>
      <h2>购物车是空的</h2>
      <p>快去添加一些商品吧！</p>
      <router-link :to="{ name: 'ProductList' }" class="shop-now-btn"> 立即购物 </router-link>
    </div>

    <div v-else class="cart-content">
      <div class="cart-items">
        <CartItem v-for="item in cartStore.items" :key="item.id" :item="item" />
      </div>

      <div class="cart-sidebar">
        <CartSummary />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useCartStore } from '@/stores/cart'

const cartStore = useCartStore()
</script>

<style scoped>
.cart-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.page-header h1 {
  margin: 0;
  color: #333;
}

.continue-shopping {
  padding: 0.5rem 1rem;
  background: #6c757d;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.continue-shopping:hover {
  background: #5a6268;
}

.empty-cart {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-cart-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-cart h2 {
  margin: 0 0 1rem 0;
  color: #333;
}

.empty-cart p {
  color: #666;
  margin-bottom: 2rem;
}

.shop-now-btn {
  display: inline-block;
  padding: 0.75rem 2rem;
  background: #007bff;
  color: white;
  text-decoration: none;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.shop-now-btn:hover {
  background: #0056b3;
}

.cart-content {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 2rem;
}

.cart-items {
  min-height: 400px;
}

@media (max-width: 768px) {
  .cart-page {
    padding: 1rem;
  }

  .page-header {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  .cart-content {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}
</style>
